"""
Case Type   : 资源池化
Case Name   : 缩容工具交互时输入【NO N no n】
Create At   : 2024.10
Owner       : chen
Description :
    1.执行缩容，交互时输入no
    2.执行缩容，交互时输入n
    3.执行缩容，交互时输入NO
    4.执行缩容，交互时输入N
Expect      :
    1.终止
    2.终止
    3.终止
    4.终止
"""

import os
import unittest
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

class SharedStorage(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_node = Node('PrimaryDbUser')
        self.db_host = Node('Standby2DbUser').db_host
        self.s_user = self.pri_node.ssh_user
        
    def test_shared_storage(self):
        param_list = ['no', 'n', 'NO', 'N']
        for i in range(4):
            text = f'''-----step{i + 1}: 执行缩容，交互时输入{param_list[i]} expect: 终止-----'''
            self.log.info(text)
            cmd = f'''source {macro.DB_ENV_PATH};
            expect <<EOF
            set timeout 600
            spawn gs_dropnode -U {self.s_user} -G {self.s_user} \
                -h {self.db_host}
            expect "*drop the target node (yes/no)?*"
            send "{param_list[i]}\\n"
            expect eof\n''' + '''EOF'''
            self.log.info(cmd)
            res = self.pri_node.sh(cmd).result()
            self.log.info(res)
            self.assertIn('Operation aborted', res)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')